<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 *
 * base_url/
 *
 * @package    controllers
 * @author     Bertrand Kintanar <bertrand.kintanar@gmail.com>
 * @version    $Id: index.php 214 2011-12-08 21:01:26Z bertrand.kintanar@gmail.com $
 * @copyright  &copy; 2011 NaCl.org WebGroup
 *
 */
class Index extends MY_Controller {

    
    public function __construct()
    {
        parent::__construct();
        parent::_get_script(__FILE__);
        
        if (ENVIRONMENT != 'development')
        {
            $this->load->spark('twitterfetcher/1.0.4');
        }
    }

    public function index()
    {
        $_article_obj = new \models\Article;
        $_articles = $_article_obj->getArticleLatestThree();

        // TODO: Move these variables to a config file
        $this->smarty->assign('page_title', 'Index page');
        
        // load jquery library and jquery rotator
        $this->smarty->assign('load_jquery', true);
        $this->smarty->assign('load_wt_rotator', true);
        
        $idx = 0;
        foreach ($_articles as $_article)
        {
            $this->smarty->assign('article_' . ++$idx, $_article);
        }
        
        // Start - get twitter feeds for @NaClOrg
        $twitterId = 'NaClOrg';
        $this->smarty->assign('twitterId', $twitterId);
        
        if (ENVIRONMENT != 'development')
        {
            $tweets = $this->twitterfetcher->getTweets(array('twitterID' => $twitterId, 'usecache' => false, 'count' => 5, 'numdays' => 30));
            $this->smarty->assign('tweets', $tweets);
        }
        // End - get twitter feeds for @NaClOrg
        
        $_navlink_obj = new \models\Navlink;
        $_events = $_navlink_obj->getNavlinkByName('Events');
        $_events_childlinks = $_navlink_obj->getNavlinkChildLinks($_events->navlink_id);
        
        $this->smarty->assign('events_navlinks', $_events_childlinks);
        
        // Load the template from the views directory
        $this->smarty->view();
    }
}
